﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.Security;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Web.Configuration;
using System.ServiceModel;
using BookClubIt.Processor;
using DTO = BookClubIt.DTO;


namespace BookClubIt
{
    public partial class editprofile : BasePage
    {
        public int CurrentUserId { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {

            string username = HttpContext.Current.User.Identity.Name.ToString();
            DTO.Member member = MemberProcessorInstance.GetMemberByUsername(username);
            int CurrentUserId = member.Id;

            txtUsername.Text = username.ToString();
            txtEmail.Text = member.Email.ToString();
            txtBio.InnerText = member.Biography.ToString();
            imgUserAvatar.ImageUrl = "../avatars/" + member.AvatarURL.ToString();
          //  lblAccountID.Text = member.Id.ToString();
          //  lblUsername.Text = username.ToString();

        }

        protected void btnEditProfile_Click(object sender, EventArgs e)
        {
            //Member member = new Member
            //{
            //    Username = RegisterUser.UserName,
            //    Email = RegisterUser.Email,
            //    CreatedDate = DateTime.Now,
            //    FirstName = string.Empty,
            //    LastName = string.Empty,
            //    Biography = string.Empty,
            //    Zipcode = string.Empty,
            //    Id = 0
            //};

          //  MemberProcessorInstance.SaveMember(member);

        }

        protected void btnUpload_Click(object sender, EventArgs e)
        {
            string username = HttpContext.Current.User.Identity.Name.ToString();
            DTO.Member member = MemberProcessorInstance.GetMemberByUsername(username);
            int CurrentUserId = member.Id;


           
            string filename = UploadImage.FileName;
            string filepath = filename;
            if (UploadImage.PostedFile.ContentLength != 0)
            {
                UploadImage.SaveAs(Server.MapPath("~/avatars/" + filename));
                MemberProcessorInstance.UpdateMemberAvatar(CurrentUserId, filepath);

            }
        }

     


    }

}